<template>
  <el-dialog @close="reset" title="编辑" :visible.sync="info.isShow">
      <el-form ref="memberForm" label-width="80px" :model="memberData" :rules="rules">
          <el-form-item label="会员账号" prop="phone">
              <el-input disabled v-model="memberData.phone"></el-input>
          </el-form-item>
          <el-form-item label="登录密码" prop="password">
              <el-input v-model="memberData.password"></el-input>
          </el-form-item>
          <el-form-item label="昵称" prop="nickname">
              <el-input v-model="memberData.nickname"></el-input>
          </el-form-item>
          <el-form-item label="状态" prop="status">
               <el-radio-group v-model="memberData.status">
                      <el-radio :label="1">正常</el-radio>
                      <el-radio :label="2">禁用</el-radio>
                  </el-radio-group>
          </el-form-item>
      </el-form>
      <div class="dialog-footer" slot="footer">
          <el-button @click="reset">取消</el-button>
          <el-button type="primary" @click="submit">提交</el-button>
      </div>
  </el-dialog>
</template>

<script>
export default {
    props:['info'],
    data(){
        return {
            // 表单数据对象
            memberData:{
                uid:'',
                phone:'',
                password:'',
                nikcname:'',
                status:''
            },
            // 表单校验规则
            rules:{
                phone:{required:true,message:'账号不能为空',trigger:'blur'},
                nickname:{required:true,message:'请输入昵称',trigger:'blur'},
                status:{required:true,message:'请选择状态',trigger:'blur'}
            }
        }
    },
    methods:{
        // 数据重置
        reset(){
            // 关闭对话框
            this.info.isShow=false;
            // 清除表单内容
            this.memberData={
                uid:'',
                phone:'',
                password:'',
                nickname:'',
                status:''
            }
        },
        submit(){
            this.$refs.memberForm.validate(valid=>{
                if(valid){
                    this.$axios.post('/memberedit',this.memberData).then(res=>{
                        if(res.code===200){
                            this.$message.success(res.msg);
                            // 更新会员数据: 通知父组件更新
                            this.$emit('memberUpdate');
                            // 重置数据
                            this.reset();
                        }else{
                            this.$message.error(res.msg);
                        }
                    })
                }
            })
        },
        // 更新表单元素
        setFormData(obj){
            this.memberData={...obj};   
            // 清除密码
            this.memberData.password='';
        }
    }
}
</script>

<style>

</style>